<template>
<div class="site-settings views-container">
  <div class="wlm-form">
    <div class="wlm-form-header">平台注册设置</div>
    <div class="wlm-form-content">
      <el-form ref="registration" :model="formFormatData.formData" :rules="formFormatData.rules" size="small" label-width="120px" class="retail-form" label-position="right" width="500">
        <el-form-item label="注册协议">
          <el-radio-group v-model="formFormatData.formData.switch">
            <el-radio label="1">打开</el-radio>
            <el-radio label="0">关闭</el-radio>
          </el-radio-group>
          <div class="form-help">注册平台时候，是否需要显示注册协议</div>
        </el-form-item>
        <el-form-item label="协议标题" prop="title" v-if="formFormatData.formData.switch==='1'">
          <el-input v-model="formFormatData.formData.title">
          </el-input>
        </el-form-item>
        <el-form-item label="协议内容" prop="content" v-if="formFormatData.formData.switch==='1'">
          <ueditor :defaultMsg='defaultMsg' :config='{initialFrameWidth: null,initialFrameHeight: 350}' ref="ue"></ueditor>
          <div class="form-help">输入不超过50字的内容</div>
        </el-form-item>
      </el-form>
    </div>
  </div>

  <!-- <div class="wlm-form">
    <div class="wlm-form-header">试用平台设置</div>
    <div class="wlm-form-content">
      <el-form ref="trial" :model="formFormatData.formData" :rules="formFormatData.rules" size="small" label-width="120px" class="retail-form" label-position="right" width="500">
        <el-form-item label="试用平台个数" prop="platNum">
          <el-input v-model="formFormatData.formData.platNum">
          </el-input>
          <div class="form-help">可创建试用平台个数</div>
        </el-form-item>
        <el-form-item label="试用天数" prop="platDay">
          <el-select v-model="formFormatData.formData.platDay" placeholder="请选择">
            <el-option v-for="item in platDayOptions" :key="item.value" :label="item.label" :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>
      </el-form>
    </div>
  </div> -->
  <div class="wlm-fixed-btn flex-row flex-align-c flex-justify-c">
    <el-button size="small" @click="saveForm" type="primary">保存</el-button>
  </div>
</div>
</template>

<script>
import {
  platformOldSet,
  platformSetting
} from '@/api/platform'
import ueditor from '@/components/Ueditor/index'
import mixins from '@/mixins/mixins'
export default {
  mixins: [mixins.getters('Form')],
  name: 'PlatformSettings',
  components: {
    ueditor
  },
  data() {
    return {
      defaultMsg: '',
      platDayOptions: [
        {
          label: '7天',
          value: '7'
        },
        {
          label: '15天',
          value: '15'
        }
      ],
      formFormatData: {
        key: ['registration', 'trial'],
        api: {
          // editForm
          editForm: {
            api: platformOldSet,
            params: {
              key: 'platform',
              always: true
            }
          },
          submitForm: platformSetting
        },
        formData: {
          switch: '1',
          title: '',
          content: '',
          platNum: '',
          platDay: '',
          key: 'platform'
        },
        rules: {
          title: [{
            required: true,
            message: '请输入协议标题',
            trigger: 'blur'
          }],
          content: [{
            required: true,
            message: '请输入协议内容',
            trigger: 'blur'
          }],
          platNum: [{
            required: true,
            message: '请输入平台个数',
            trigger: 'blur'
          }],
          platDay: [{
            required: true,
            message: '请输入试用天数',
            trigger: 'blur'
          }]
        }
      }
    }
  },
  methods: {
    saveForm() {
      if (this.formFormatData.formData.switch !== '0') {
        this.ueditorChange()
      }
      this.formFormatSubmit()
    },
    ueditorChange() {
      this.formFormatData.formData.content = this.$refs.ue.getUEContent('getContent')
    },
    formFormatCallBack(data, type) {
      if (type === 'editForm') {
        const { content = '' } = data
        this.defaultMsg = content
      }
    }
  }
}
</script>
